package com.rjxy.plansystemmanagement.controller.entityController;

import com.rjxy.plansystemmanagement.entity.FlightInformation;
import com.rjxy.plansystemmanagement.entity.HotelInformation;
import com.rjxy.plansystemmanagement.entity.Result.Result;
import com.rjxy.plansystemmanagement.service.HotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Hotels")
@Slf4j
public class HotelController {
    @Autowired
    private HotelService hotelService;

    /**
     * 查询所有酒店
     * @return
     */
    @GetMapping
    public Result list(){
        log.info("查询酒店列表");
        //调用service查询用户数据
        List<HotelInformation> hotelInformationList = hotelService.list();
        return Result.success(hotelInformationList);
    }

    /**
     * 根据id删除指定酒店
     * @param ID
     * @return
     */
    @DeleteMapping("/{ID}")
    public  Result deleteHotel(@PathVariable Integer ID){
        log.info("根据{HotelID}删除指定酒店",ID);
        hotelService.deleteHotel(ID);
        return Result.success();
    }

    /**
     * 增加酒店信息
     * @param hotelInformation
     * @return
     */
    @PostMapping
    public Result addHotel(@RequestBody HotelInformation hotelInformation){
        log.info("插入酒店信息");
        hotelService.addHotel(hotelInformation);
        return Result.success();
    }

    /**
     * 根据ID查询酒店
     * @param ID
     * @return
     */
    @GetMapping("/{ID}")
    public Result getHotelById(@PathVariable Integer ID){
        log.info("根据{id}查询酒店",ID);
        HotelInformation hotelInformation = hotelService.getHotelById(ID);
        return Result.success(hotelInformation);
    }

    @GetMapping("/search")
    public Result searchHotels(@RequestParam(required = false) String hotelAddress,
                               @RequestParam(required = false) String hotelStar,
                               @RequestParam(required = false) String hotelTheme,
                               @RequestParam(required = false) String hotelFacilities) {
        log.info("根据条件搜索酒店: 地址={}, 星级={}, 主题={}, 设施={}", hotelAddress, hotelStar, hotelTheme, hotelFacilities);
        List<HotelInformation> hotelInformationList = hotelService.searchHotels(hotelAddress, hotelStar, hotelTheme, hotelFacilities);
        return Result.success(hotelInformationList);
    }

    /**
     * 根据酒店地址查询
     * @param hotelAddress
     * @return
     */
    @GetMapping("/Address/{HotelAddress}")
    public Result getHotelByAddress(@PathVariable("HotelAddress") String hotelAddress){
        log.info("根据酒店地址查询{}",hotelAddress);
        List<HotelInformation> hotelInformationList = hotelService.getHotelByAddress(hotelAddress);
        return Result.success(hotelInformationList);
    }

    /**
     * 根据酒店星级查询
     * @param hotelStar
     * @return
     */
    @GetMapping("/Star/{HotelStar}")
    public Result getHotelByStar(@PathVariable("HotelStar") String hotelStar){
        log.info("根据星级{}查询酒店",hotelStar);
        List<HotelInformation> hotelInformationList = hotelService.getHotelByStar(hotelStar);
        return Result.success(hotelInformationList);
    }

    /**
     * 根据酒店名称查询
     * @param HotelName
     * @return
     */
    @GetMapping("/Name/{HotelName}")
    public Result getHotelByName(@PathVariable String HotelName){
        log.info("根据酒店名字{}查找",HotelName);
        HotelInformation hotelInformation = hotelService.getHotelByName(HotelName);
        return Result.success(hotelInformation);
    }

    @GetMapping("/Theme/{HotelTheme}")
    public Result getHotelByTheme(@PathVariable("HotelTheme") String hotelTheme){
        log.info("根据主题{}查询酒店",hotelTheme);
        List<HotelInformation> hotelInformationList = hotelService.getHotelByTheme(hotelTheme);
        return Result.success(hotelInformationList);
    }

    @GetMapping("/Facilities/{Facilities}")
    public Result getHotelByFacilities(@PathVariable("Facilities") String hotelFacilities){
        log.info("根据设施{}查询酒店",hotelFacilities);
        List<HotelInformation> hotelInformationList = hotelService.getHotelByFacilities(hotelFacilities);
        return Result.success(hotelInformationList);
    }


    @PutMapping
    public Result updateHotel(@RequestBody HotelInformation hotelInformation){
        //log.info("Received hotel information: {}", hotelInformation);
        log.info("更新id为{}的航班",hotelInformation.getID());

        hotelService.updateHotel(hotelInformation);
        return Result.success();
    }


}
